import { Breadcrumb } from 'antd';
import { items } from './Menu';
import { useLocation } from 'umi';

export default () => {
  const { pathname } = useLocation();

  const arr = pathname.split('/');
  // /index/banner/list -> ["", "index", "banner", "list"]
  let firstname = '';
  let lastname = '';
  items.forEach((item: any) => {
    if (item.key === '/' + arr[2]) {
      firstname = item.label;
      if (item.children) {
        item.children.forEach((val: any) => {
          if (val.key === '/' + arr[2] + '/' + arr[3]) {
            lastname = val.label;
          }
        });
      }
    }
  });

  return (
    <Breadcrumb style={{ margin: '16px 0' }}>
      <Breadcrumb.Item>系统首页</Breadcrumb.Item>
      <Breadcrumb.Item>{firstname}</Breadcrumb.Item>
      <Breadcrumb.Item>{lastname}</Breadcrumb.Item>
    </Breadcrumb>
  );
};
